<?php
if(!defined("GUARD"))
{
    die("No direct script access allowed!");
}

/**
 * Description of connectorclass
 *
 * @author Nick
 */
class Sigma_Connector
{
/**
 *
 * @var Array The settings array
 */
    private $settings = Array
    (
    "host"     => "localhost",
    "username" => "root",
    "password" => "",
    "port"     => "3306", // The default is 3306, but you may need to change it
    "db"       => "MicroBlogger"
    );
    public $link = NULL;
    private $results = NULL;
    public $rows;
    /**
     *
     * @return Connector
     */
    public function __construct()
    {
        $this->link = mysql_connect($this->settings["host"], $this->settings["username"], $this->settings["password"]);
        if(!$this->link)
        {
            echo "Mysql error: " . mysql_error();
        }
        else
        {
            mysql_select_db($this->settings["db"], $this->link);
        }
        return $this;
    }

    /**
     *
     * @param string $sql
     * @return Connector
     */
    public function query($sql)
    {
        $this->query = trim($sql);
        return $this;
    }
    /**
     *
     * @return boolean
     */
    public function exec()
    {
        if(get_magic_quotes_gpc() == 1)
        {
            $this->results = mysql_query(mysql_real_escape_string(addslashes($this->query)), $this->link);
            $this->rows = mysql_fetch_assoc($this->results);
            return true;

        }
        else
        {
            $this->results = mysql_query(mysql_real_escape_string($this->query), $this->link);
            $this->rows = mysql_fetch_assoc($this->results);
            return true;
        }
        return false;
    }



}
?>
